/*
 * ULSF Sagittarius IDA Jones Panel
 * Copyright (C) 2002, Kevin Jones, all rights reserved.
 * Copyright (C) 2012, John Pritchard, all rights reserved.
 * 
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package sagittarius.panel;

/**
 * Java port of Kevin's Online Panel Code.
 * @see http://aa.nps.edu/~jones/online_tools/panel2
 * @see Panel
 */
public class Main {

    public static void main(String[] argv){
        if (16 == argv.length){

            try {
                boolean use_naca = "true".equals(argv[0]);

                int naca = 0;
                if (use_naca)
                    naca = Integer.parseInt(argv[1]);

                String airfoil = argv[2];

                boolean smoothing = "true".equals(argv[3]);

                int npanels = Integer.parseInt(argv[4]);

                float alphad = Float.parseFloat(argv[5]);

                float xcp = Float.parseFloat(argv[6]);

                float ycp = Float.parseFloat(argv[7]);

                boolean show_cp = "true".equals(argv[8]);

                boolean show_st = "true".equals(argv[9]);

                boolean show_pr = "true".equals(argv[10]);

                boolean show_gr = "true".equals(argv[11]);

                boolean show_vv = "true".equals(argv[12]);

                int width = Integer.parseInt(argv[13]);
       
                int x0 = Integer.parseInt(argv[14]);

                int y0 = Integer.parseInt(argv[15]);

                Panel.Inputs inputs;

                if (use_naca){

                    inputs = new Panel.Inputs(naca, smoothing, npanels, alphad, xcp, ycp,
                                        width, x0, y0);
                }
                else {

                    inputs = new Panel.Inputs(UIUC.For(airfoil), smoothing, npanels, alphad, xcp, ycp,
                                        width, x0, y0);
                }

                Panel panel = new Panel(inputs);
                panel.init();

                if (show_gr || show_vv || show_pr){
                    panel.loadGrid();
                    if (show_pr || show_vv)
                        panel.loadFieldVars();
                }
                if (show_st)
                    panel.loadStreamLines();

                panel.printForces();
                panel.printFoil();
                if (show_pr)
                    panel.printFieldPres();
                if (show_gr)
                    panel.printGrid();
                if (show_vv)
                    panel.printVectors();
                if (show_st)
                    panel.printStreamLines();
                if (show_cp)
                    panel.printCp();
            }
            catch (Exception exc){
                exc.printStackTrace();
                System.exit(1);
            }
        }
        else {
            System.err.println("Requires same parameters as Kevin's Online Panel Code (v2).");
            System.exit(1);
        }
    }
}
